package com.example.xiaosen.controller;

import lombok.RequiredArgsConstructor;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.memory.ChatMemory;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

/**
 * @Author: zhouxj@ferrotec.com.cn
 * @version: v1.0
 * @Date: 2025/5/13 14:46
 * @Description:
 */
@RequiredArgsConstructor
@RestController
@RequestMapping("/ai")
public class GameController {

    private final ChatClient gameClient;

    /**
     * 基于纯Prompt开发的小游戏，通过设计提示词实现功能限制和输入输出格式规范
     * @param prompt
     * @param chatId
     * @return
     */
    @RequestMapping(value = "/game", produces = "text/html;charset=utf-8")
    public Flux<String> chat(String prompt, String chatId) {
        return gameClient.prompt()
                .user(prompt)
                .advisors(a -> a.param(ChatMemory.CONVERSATION_ID,
                        chatId))
                .stream()
                .content();
    }
}
